package com.imooc.pan.bloom.filter.local;


import com.google.common.hash.Funnel;
import com.imooc.pan.bloom.filter.core.BloomFilter;

/**
 * @Description: 本地实现的布隆过滤器
 * @Author: 张广焱
 * @Date: 2024-12-05 14:03
 */
public class LocalBloomFilter<T> implements BloomFilter<T> {

    private com.google.common.hash.BloomFilter delegade;

    /**
     * 数据通道
     */
    private Funnel funnel;
    /**
     * 数组的长度
     */
    private long expectedInsertions;
    /**
     * 误判率
     */
    private double fpp;

    public LocalBloomFilter(Funnel funnel, long expectedInsertions, double fpp) {
        this.funnel = funnel;
        this.expectedInsertions = expectedInsertions;
        this.fpp = fpp;
        this.delegade = com.google.common.hash.BloomFilter.create(funnel, expectedInsertions, fpp);
    }

    @Override
    public boolean put(T object) {
        return delegade.put(object);
    }

    @Override
    public boolean mightContain(T object) {
        return delegade.mightContain(object);
    }

    @Override
    public void clean() {
        this.delegade = com.google.common.hash.BloomFilter.create(funnel, expectedInsertions, fpp);
    }
}
